﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Bubblez
{
    public partial class frmnewfilter : Form
    {
        // External Filters
        public string Filter;
        public string Filter_Name;
        public string Filter_String;
        public bool Filter_Title;
        public bool Filter_Author;
        public bool Filter_Notes;
        public bool Filter_HasDep;
        public int Filter_Mode;
        public bool Filter_Enabled;

        public bool Reload = false;

        public frmnewfilter()
        {
            InitializeComponent();
        }

        private void Filter_Save(string path)
        {
            //if (create == false)
            string[] f = new string[] { "Name=" + txtName.Text, "String=" + txtString.Text, "Title=" + Convert.ToString(chkTitle.Checked), "Author=" + Convert.ToString(chkAuthor.Checked), "Notes=" + Convert.ToString(chkNotes.Checked), "HasDep=" + Convert.ToString(chkdep.Checked), "Mode=" + Convert.ToString(Get_Mode()), "Enabled=" + Convert.ToString("True") };
            File.WriteAllLines(path, f);
        }
        private int Get_Mode()
        {
            if (rdoExact.Checked == true)
                return 1;
            else if (rdoMatch.Checked == true)
                return 2;
            else if (rdoContains.Checked == true)
                return 3;
            else
                return 0;
        }
        private string Get_FileName(string n)
        {
            string r = n.Replace(' ', '_');
            return r;

        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void cmdCreate_Click(object sender, EventArgs e)
        {
            if ((txtName.Text != "") && (txtString.Text != ""))
            {
                Filter_Save (Application.StartupPath + "\\Filters\\" + Get_FileName(txtName.Text) + ".filter");
            }
            Reload = true;
            this.Close();
        }
    }
}
